from typing import List

class Solution:
    def longestSubarray(self, nums: List[int]) -> int:
        max_val = max(nums)
        n = len(nums)
        i = 0
        ans = 1
        while i < n:
            if nums[i] == max_val:
                j = i
                while j < n and nums[j] == max_val:
                    ans = max(ans, j - i + 1)
                    j += 1
                else:
                    i = j
            i += 1
        return ans

if __name__ == '__main__':
    s = Solution()
    r = s.longestSubarray([1,2,3,3,2,2])
    print(r)